package com.gitee.shigen.lucene.util;

import com.gitee.shigen.lucene.vo.Content;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.TextField;

public class DocumentUtil {

    public static Document Content2Document(Content content) {
        Document document = new Document();
        document.add(new TextField("id", String.valueOf(content.getId()), Field.Store.YES));
        document.add(new TextField("title", content.getTitle(), Field.Store.YES));
        document.add(new TextField("price", content.getPrice(), Field.Store.YES));
        document.add(new TextField("img", content.getImg(), Field.Store.YES));
        document.add(new TextField("desc", content.getDesc(), Field.Store.YES));
        return document;
    }

    public static Content document2Content(Document doc) {
        Content content = new Content();

        content.setId(Integer.parseInt(doc.get("id")));
        content.setTitle(doc.get("title"));
        content.setPrice(doc.get("price"));
        content.setImg(doc.get("img"));
        content.setDesc(doc.get("desc"));
        return content;
    }
}
